// we7/pages/index/evaluateMore.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    limit: 8,
    allEvaluate:"",
    goods_evaluate_star:'',
    goods_evaluate_image:"",
    goods_id:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.goods_id)
    wx.setNavigationBarTitle({
      title: '用户评价',
    })
 
    var that = this;
    that.setData({
      goods_id: options.goods_id
    })
    app.util.request({
      url: 'admin/WxGoodsApi/allEvaluate',
      data: {
        goods_id: options.goods_id,
        page:1,
        limit: that.data.limit
      },
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.code == 0) {
         var data=res.data.data
          for (var i = 0; i < data.length; i++) {
            var arr=[]
            // console.log(data[i].goods_evaluate_star)
            for (var j = 0; j < data[i].goods_evaluate_star; j++) {
              arr[j] = j + 1
            }
            // console.log(arr)
            var goods_evaluate_image = data[i].goods_evaluate_image.split(",")
            if (goods_evaluate_image){
              var arrImg = [];
              for (var m = 0; m < goods_evaluate_image.length; m++) {
                arrImg[m] = app.globalData.url + goods_evaluate_image[m];
              }
              data[i]["goods_evaluate_image"] = arrImg;
            }
            data[i]['xx']=arr;
          }
         that.setData({
           allEvaluate: data
         })
        }

      },
      fail: function (res) {
        wx.showToast({
          title: "服务器无响应",
          icon: 'none',
          duration: 2000
        })
      }

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page=that.data.page
    var pages=++page
    that.setData({
      page:pages
    })
    console.log(pages)
    console.log(that.data.goods_id)
    var allEvaluate = that.data.allEvaluate
    app.util.request({
      url: 'admin/WxGoodsApi/allEvaluate',
      data: {
        goods_id: that.data.goods_id,
        page: pages,
        limit: that.data.limit
      },
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.code == 0) {
          var data = res.data.data
          for (var i = 0; i < data.length; i++) {
            var arr = []
            console.log(data[i].goods_evaluate_star)
            for (var j = 0; j < data[i].goods_evaluate_star; j++) {
             
              arr[j] = j + 1
            }
            var goods_evaluate_image = data[i].goods_evaluate_image.split(",")
            if (goods_evaluate_image) {
              var arrImg = [];
              for (var m = 0; m < goods_evaluate_image.length; m++) {
                arrImg[m] = app.globalData.url + goods_evaluate_image[m];
              }
              data[i]["goods_evaluate_image"] = arrImg;
            }
            allEvaluate.push(data[i])
            data[i]['xx'] = arr;
          }
         
          that.setData({
            allEvaluate: data,
            allEvaluate: allEvaluate
          })
        }

      },
      fail: function (res) {
        wx.showToast({
          title: "服务器无响应",
          icon: 'none',
          duration: 2000
        })
      }

    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})